/*******************************************************************************
Project:        Rents
Last modified:  2024-01-16
Description:    This file creates a figure displaying the shares of each type of income earned by wealth quintiles, breaking out additional information at the top. 
*******************************************************************************/

clear all

global home "V:\sthorpe\Rents\Corporate Profits and Risk Premia"
global output "$home\output"

global gpr = "plotregion(fcolor(white) lcolor(white) m(tiny)) graphregion(fcolor(white) lcolor(white))"

cd "$home"


import excel "risk_returns_data_clean.xlsx", firstrow clear

drop F G H 

#delimit ;
twoway area yr_treasury year, lcolor(navy) color(navy) || rarea yr_treasury risky_return year, lcolor(maroon) color(maroon)
legend(order(1 "Risk-Free Return" 2 "Risk Premium")
                    size(small) region(lcolor(white) margin(tiny)) row(1)
                    symxsize(*0.4) position(6)) xsize(7); 
					
 graph export "$output/stackedarea_risk_returns.png", replace ;
		#delimit cr 

		
**#rolling average plot
clear all

import excel "profits_data_clean", firstrow
drop I 

gen avg_pretax_gdp_c = . 
gen avg_aftertax_gdp_c = . 

foreach n in numlist 1984/2020 {
replace avg_pretax_gdp_c = (pretax_gdp_c[_n-2] + pretax_gdp_c[_n-1] + pretax_gdp_c[_n])/3
replace avg_aftertax_gdp_c = (aftertax_gdp_c[_n-2] + aftertax_gdp_c[_n-1] + aftertax_gdp_c[_n])/3
}

replace avg_pretax_gdp_c = pretax_gdp_c if year==1982 | year==1983 | year==1993 | year==1996 
replace avg_aftertax_gdp_c = aftertax_gdp_c if year==1982 | year==1983 | year==1993 | year==1996 
//smoothing years around the SOI data gap

		twoway (scatter avg_pretax_gdp_c year, c(l) mcolor(navy) lcolor(navy) ms(O) msize(small)) ///
			(scatter avg_aftertax_gdp_c year, c(l) mcolor(maroon) lcolor(maroon) ms(T) msize(small) lpattern(dash)), ///
			xtitle("Year") xlab(1982(5)2020, valuelabel labsize(small)) ///
			ytitle("Percentage of GDP") ylab(0(2)10) ///
			legend(on order(1 2) lab(1 "Pre-Tax Profits, C-Corporations") lab(2 "After-Tax Profits, C-Corporations") row(1) position(6) ///
			region(lcolor(white)) symxsize(8)) ///
			graphregion(lcolor(white) fcolor(white)) plotregion(color(white)) xsize(7)
				graph export "output/profits_gdp_c_3yearavg.png", replace 
			